package com.ocom.webapi.controller;

import com.alibaba.fastjson.JSONObject;
import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.request.payconfig.xfwalletinfo.GetConsAllWalletRequest;
import com.ocom.common.request.payconfig.xfwalletinfo.GetConsWalletListRequest;
import com.ocom.common.request.payconfig.xfwalletinfo.SetConsAllWalletRequest;
import com.ocom.common.request.payhandle.QrCodePayRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.NumConvertUtil;
import com.ocom.webapi.feign.PayConfigClientService;
import com.ocom.webapi.feign.PayHandleFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class JHSHController {

    @Autowired
    private PayHandleFeignService payHandleFeignService;

    @PostMapping("/jhsh/pay")
    public Result consWalletInfo(@RequestBody JSONObject request) {

        QrCodePayRequest qrCodePayRequest = new QrCodePayRequest();
        qrCodePayRequest.setCompanyId(request.getLong("companyId"));
        qrCodePayRequest.setMachNo(request.getString("machNo"));
        qrCodePayRequest.setTradeNo(request.getString("orderNo"));
        qrCodePayRequest.setAmount(request.getIntValue("amount"));//分

        JSONObject object = new JSONObject();
        object.put("qrCode",request.getString("qrCode"));
        object.put("businessId",request.getString("businessId"));
        object.put("vposId",request.getString("vposId"));
        object.put("couponInfo",request.getString("couponInfo"));
        object.put("accNos",request.getString("accNos"));
        object.put("offline",request.getString("offline"));
        object.put("signTime",request.getString("signTime"));

        String param = "JHSH" + NumConvertUtil.stringToHexString(object.toString());
    //    System.out.println("param:" + param);

        qrCodePayRequest.setAuthCode(param);
        qrCodePayRequest.setConsType(request.getIntValue("consType"));

        return  payHandleFeignService.qrCodePay(qrCodePayRequest);
    }


}
